From: Timo Tijhof Date: Fri, 4 Apr 2014 01:50:54 +0000 (-0700) Subject: resourceloader: Don't add superfluous line breaks and semicolons X-Git-Tag: 1.31.0-rc.0~16329^2 X-Git-Url: http://git.cyclocoop.org/%7D%7Cconcat%7B?a=commitdiff_plain;h=f039edc7d57a2e8d8d381094c363a69dc0dff556;p=lhc%2Fweb%2Fwiklou.git resourceloader: Don't add superfluous line breaks and semicolons The logic was there but didn't work in practice because, just like this code does itself, code doesn't usually end in ';'. Instead it ends in ";\n" (trailing line break at end of file), or even two line breaks (in case of concatenated scripts where ResourceLoaderFileModule adds another line break). This saves off a few bytes that were uselessly added in the load.php output, like: ... }( jQuery ) ); ; /** ... After this: }( jQuery ) ); /** The logic to add ;\n is still there, but the logic to not add it when there already wasn't working (added in I3e8227ddb). Change-Id: Ie055b37b3419ac6dca6349daf745bc48850fff3e --- diff --git a/includes/resourceloader/ResourceLoader.php b/includes/resourceloader/ResourceLoader.php index b2fb902cfa..77659f68eb 100644 --- a/includes/resourceloader/ResourceLoader.php +++ b/includes/resourceloader/ResourceLoader.php @@ -795,9 +795,11 @@ class ResourceLoader { $scripts = $module->getScriptURLsForDebug( $context ); } else { $scripts = $module->getScript( $context ); - if ( is_string( $scripts ) && strlen( $scripts ) && substr( $scripts, -1 ) !== ';' ) { - // bug 27054: Append semicolon to prevent weird bugs - // caused by files not terminating their statements right + // rtrim() because there are usually a few line breaks after the last ';'. + // A new line at EOF, a new line added by ResourceLoaderFileModule::readScriptFiles, etc. + if ( is_string( $scripts ) && strlen( $scripts ) && substr( rtrim( $scripts ), -1 ) !== ';' ) { + // Append semicolon to prevent weird bugs caused by files not + // terminating their statements right (bug 27054) $scripts .= ";\n"; } }